import matplotlib.pyplot as plt


class dataset(object):
    def __init__(self, path):
        self.dataMat, self.labelMat = self.loadDataSet(path)

    @staticmethod
    def loadDataSet(path):
        with open(path, "r", encoding='UTF-8') as f:
            data = f.readlines()

        Data = []
        Label = []
        for line in data:
            data = list(map(float, line.strip().split()))
            Data.append(data[:2])
            Label.append(data[-1])
        return Data, Label

    @classmethod
    def Drawdata(cls):
        Data, Label = cls.loadDataSet("./data/data.txt")
        fig = plt.figure()
        ax = fig.add_subplot(111)
        for i, data in enumerate(Data):
            if Label[i] == 1:
                ax.scatter(data[0], data[1], s=15, c='red', marker='s', alpha=.5)
            else:
                ax.scatter(data[0], data[1], s=20, c='green', marker='x', alpha=.5)
        plt.xlabel("x1"), plt.ylabel("x2")
        plt.title("data")
        return plt, ax


# plt, ax = data.Drawdata()
# plt.show()
